package com.Web_02;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ResponseDemo2", value = "/ResponseDemo2")
public class ResponseDemo2 extends HttpServlet {

//    重定向：是资源跳转的方式--->用户访问AServlet后，服务器告诉浏览器重定向到BServlet

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        PrintWriter writer = response.getWriter();
        writer.write("ResponseDemo3....执行了");
        System.out.println("ResponseDemo2。。。。。执行了");
 /*       //            设置状态码
        response.setStatus(302);
//        设置响应头  Location,即在ResponseDemo2运行后会自动跳转到ResponseDemo3
        response.setHeader("Location","/JavaWeb_02/ResponseDemo3")*/;

//        重定向到Servlet,地址写绝对路径，如果是服务器内部的资源  http://localhost:8080可以不写
//        response.sendRedirect("/JavaWeb_02/ResponseDemo3");
//         该重定向可以转到外部服务器
//        response.sendRedirect("https://www.douyin.com");
    }
}
